package com.wodogs.utils;

import org.apache.commons.lang3.StringUtils;

import com.wodogs.utils.bean.WfProxy;
import com.wodogs.utils.service.ListData;

public class BaseRunnable implements Runnable {
	
	protected BaseManage manage;
	
	protected ListData listData;

	public BaseRunnable(ListData listData) {
		this.setListData(listData);
	}
	
	public WfProxy getProxy(String last_proxy){
		if(listData.getProxyIdList() == null || listData.getProxyIdList().size()<1){
			return null;
		}
		if(StringUtils.isNotBlank(last_proxy)&&listData.getProxyIdList().indexOf(last_proxy)>-1){
			return listData.getProxyList().get(listData.getProxyIdList().indexOf(last_proxy));
		}
		if(listData.getProxyUnusedList().size()<0){
			return null;
		}
		int index1 = (int)(Math.random()*(listData.getProxyUnusedList().size()-1));
		return listData.getProxyUnusedList().remove(index1);
	}

	public BaseRunnable() {
		super();
	}

	public BaseManage getManage() {
		return manage;
	}

	public void setManage(BaseManage manage) {
		this.manage = manage;
	}

	public ListData getListData() {
		return listData;
	}

	public void setListData(ListData listData) {
		this.listData = listData;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}
	
}
